local skel = fk.CreateSkill{
  name = "ksp__shiluan",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["ksp__shiluan"] = "始乱",
  [":ksp__shiluan"] = "锁定技，你的手牌均明置。每名角色每回合限一次，没有“始乱”的角色可以使用你的一张手牌："..
  "若你为目标之一，你回复一点体力；若其为目标之一，你摸两张牌。",

  ["$ksp__shiluan1"] = "你们的争斗，不过是我指间的傀儡戏。",
  ["$ksp__shiluan2"] = "我动动指尖，便能让山河变色，群雄皆醉。",
}

skel:addEffect("visibility",{
  card_visible = function(self, player, card)
    local room = Fk:currentRoom()
    local owner = room:getCardOwner(card.id)
    if owner and table.contains(owner.player_cards[Player.Hand], card.id) and owner:hasSkill(skel.name) then
      return true
    end
  end
})

skel:addEffect("filter", {
  handly_cards = function (self, player)
    if player:hasSkill(skel.name) then return {} end
    local list = {}
    local temp = player:getNextAlive()
    while temp ~= player do
      if temp:hasSkill(skel.name) and not table.contains(player:getTableMark("ksp__shiluan_use-turn"),temp.id) then
        for _,cid in ipairs(temp:getCardIds("h"))do
          table.insertIfNeed(list,cid)
        end
      end
      temp = temp:getNextAlive()
    end
    return list
  end,
})

skel:addEffect(fk.PreCardUse,{
  can_refresh = function (self, event, target, player, data)
    local room = player.room
    return player:hasSkill(skel.name) and data.from ~= player and room:getCardOwner(data.card.id) == player and not table.contains(data.from:getTableMark("ksp__shiluan_use-turn"),player.id)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:addTableMark(data.from,"ksp__shiluan_use-turn",player.id)
    room:addTableMark(player,"ksp__shiluan_cid-turn",data.card.id)
  end,
})

skel:addEffect(fk.CardUsing,{
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and
    table.contains(player:getTableMark("ksp__shiluan_cid-turn"),data.card.id)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:removeTableMark(player,"ksp__shiluan_cid-turn",data.card.id)
    if table.contains(data.tos,player) then
      if player:isWounded() then
          room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = skel.name
        }
      end
    end
    if table.contains(data.tos,data.from) then
      room:drawCards(player,2,skel.name)
    end
  end,
})

return skel